<template>
	<div v-show="showPage">
		<div style="border-bottom: 1px solid #ddd;">
			<h3>关联表</h3>
		</div>
		<div style="margin-top: 10px;">
			关联表
			<el-select size="mini" v-model="tableName" placeholder="请选择" clearable filterable
				@change="onTableSelectChangeHandler">
				<el-option v-for="item in modelList" :key="item.value" :label="item.name" :value="item.value">
				</el-option>
			</el-select>
		</div>
		<div style="margin-top: 10px;">
			关联字段
			<el-select size="mini" v-model="selectedColumnList" placeholder="请选择" clearable filterable multiple>
				<el-option v-for="item in columnList" :key="item.value" :label="item.name" :value="item.value">
				</el-option>
			</el-select>
		</div>
	</div>
</template>

<script>
	import restUtil from '@/utils/restUtil.js';
	export default {
		name: "ModelSelectPage",
		props: ["scope"],
		data() {
			return {
				showPage: false,
				modelList: [],
				tableName: "",
				columnList: [],
				selectedColumnList: [],
			}
		},
		mounted() {

		},
		methods: {
			init() {
				var that = this;
				restUtil.getAction(this,"webide/workflowwizarddialog/initModelSelectPage").then(
					function(response) {
						if (response.data.code == 1) {
							that.modelList = response.data.tableList;
						} else {
							that.$alert(response.data.message, '提示')
						}
					});
			},
			setVisible(visible) {
				this.showPage = visible;
				if (visible) {
					if (this.modelList.length == 0) {
						this.init();
					}
				}
			},
			getReturnData() {
				var data = {
					"tableName": this.tableName,
					"displayColumList":this.selectedColumnList
				};
				return data;
			},
			getPreviousPage() {
				return "moduleTypeSelectPage";
			},
			getNextPage() {
				return "workflowBaseInfoPage";
			},
			isCompletedPage() {
				return false;
			},
			onTableSelectChangeHandler() {
				var that = this;
				restUtil.getAction(this,"webide/workflowwizarddialog/onTableSelectChangeHandler?tableName="+this.tableName).then(
					function(response) {
						if (response.data.code == 1) {
							that.selectedColumnList=[];
							that.columnList = response.data.columnList;
						} else {
							that.$alert(response.data.message, '提示')
						}
					});
			}
		},
	}
</script>

<style>
</style>
